package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.damain.Category;
import com.itheima.reggie.damain.Dish;
import com.itheima.reggie.mapper.CategoryMapper;
import com.itheima.reggie.service.CategorySerivce;
import com.itheima.reggie.service.DishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    private CategorySerivce categorySerivce;
//    @Autowired
//    private CategoryMapper categoryMapper;
//    @Autowired
//    private DishService dishService;
    //查询所有
    @GetMapping("/category/findAll")
    public ResultInfo findall(){
        List<Category>categoryList=categorySerivce.findall();
        return ResultInfo.success(categoryList);
    }

    //新增
    @PostMapping("/category")
    public ResultInfo save(@RequestBody Category category){

        categorySerivce.save(category);
        return ResultInfo.success(null);
    }

    //修改分类
    @PutMapping("/category")
    public ResultInfo update(@RequestBody Category category){
        categorySerivce.update(category);
        return ResultInfo.success(null);
    }
    //删除分类
    @DeleteMapping("/category")
    public ResultInfo delete(Long id){
        ResultInfo resultInfo=categorySerivce.delete(id);
        return resultInfo;
    }
    //根据type查询分类信息
    @GetMapping("/category/list")
    public ResultInfo fingbytype(Integer type){
        List<Category> categoryList = categorySerivce.findByType(type);
        return ResultInfo.success(categoryList);
    }
//    //批量删除
//    @DeleteMapping("/dish")
//    public ResultInfo deleteByIds(@RequestParam("ids") List<Long> ids){
//        dishService.deleteByIds(ids);
//        return ResultInfo.success(null);
//    }

}
